#include <iostream>
#include <unordered_set>
#include <vector>

using namespace std;

void cin_map(vector<vector<int>>& map)
{
	for (auto& r : map)
	{
		for (auto& it : r)
		{
			cin >> it;
		}
	}
}

class Solution
{
public:
	int check(const vector<vector<int>>& map)
	{
		vector<unordered_set<int>> row(9);
		vector<unordered_set<int>> colum(9);
		vector<unordered_set<int>> block(9);
		for (int i = 0; i < 9; ++i)
		{
			for (int j = 0; j < 9; ++j)
			{
				if (1 > map[i][j] || map[i][j] > 9)
				{
					return 0;
				}
				row[i].insert(map[i][j]);
				colum[j].insert(map[i][j]);
				block[i / 3 * 3 + j / 3].insert(map[i][j]);
			}
		}
		for (int i = 0; i < 9; ++i)
		{
			if (row[i].size() != 9 || colum[i].size() != 9 || block[i].size() != 9)
			{
				return 0;
			}
		}
		return 1;
	}
};

int main()
{
	int n;
	cin >> n;
	Solution solu;
	vector<vector<int>> map(9, vector<int>(9, 0));
	for (int _ = 0; _ < n; ++_)
	{
		if (_)
		{
			cout << endl;
		}
		cin_map(map);
		cout << solu.check(map);
	}
	return 0;
}
